package com.core.safe;

import com.core.comment.StringUtil;
import com.core.netty.http.Intercept.MyIntercept;
import com.core.netty.http.work.HttpMyReponse;
import com.core.netty.http.work.HttpMyRequest;

import java.util.Map;

//@Intercept("/*")
public class MySafeIntercept implements MyIntercept {

    @Override
    public void doFilter(HttpMyRequest request, HttpMyReponse reponse) {
        System.out.println("进了shiro拦截器了");
        Map<String, Object> filter = SafeCache.getFilter().getFilterMap();
        String token = request.getHeaders().get("token");
        if (StringUtil.isNotBlack(token)) {
            String ip = request.getRemoteHost();
            if (StringUtil.isNotBlack(ip)) {

                MySubject mySubject = MySubject.getInstance(ip);
                if (!mySubject.isLogUrl(request.getUrl())) {

                    if (!mySubject.valid(token)) {
                        reponse.fullWrite("请重新登录");
                    }
                    if (!mySubject.validUrl(token, request.getUrl())) {
                        reponse.fullWrite("该url不允许访问");
                    }
                }

            }
        }
    }
}
